package com.sun.lib.base;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sun.lib.util.EventBusUtil;

import butterknife.ButterKnife;
import io.reactivex.disposables.CompositeDisposable;

/*
 * Created by Administrator on 2019/7/23.
 *
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
public abstract class BaseActivity extends AppCompatActivity {
    protected BaseActivity context;
    private CompositeDisposable disposable;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initBeforeLoadView();
        int layoutResId = getLayoutResID();
        if (layoutResId != 0)
            setContentView(layoutResId);
        if (isBindEventBus()) {
            EventBusUtil.register(this);
        }
        ButterKnife.bind(this);
        context = this;
        getExtraEvent(getIntent().getExtras());
        ARouter.getInstance().inject(this);
        initialize(savedInstanceState);
    }

    public CompositeDisposable getDisposable(){
        return disposable;
    }

    protected abstract void getExtraEvent(Bundle extras);

    protected abstract boolean isBindEventBus();

    protected abstract void initialize(Bundle savedInstanceState);

    protected void initBeforeLoadView() {
    }

    protected abstract int getLayoutResID();

    @Override
    protected void onDestroy() {
        if (isBindEventBus()) {
            EventBusUtil.unregister(this);
        }
        super.onDestroy();
    }
}
